declare let JIM: any;
module MC.Call {

    /** 极光的用户名 */
    let uid: string;
    let pass: string;
    let LoadFun: Function = null;
    let AudioQueue:MC.AudioModel.Audio = null;//new MC.AudioModel.Audio;
    export function Jiguang(_fun: Function) {
        AudioQueue=new MC.AudioModel.Audio;
        MC.loadJsUrl('/h5/js/jiguang.js', () => { 
            LoadFun = _fun;
            window.JIM = new JMessage({
                debug: false//true false
            });
            MC.api('getjiguang', {}, (data: any) => {
                uid = data[4]
                ///  MC.user.getInfo(this.uid);
                pass = data[5];
                JiguangInit(data[0], data[1], data[2], data[3]);
                ///	console.log(data);
            });
        });
         AudioQueue.addFile("msg", "/media/msg.mp3");
          AudioQueue.load("",()=>{
			});
    }
    export function newmsgAudio() {
        AudioQueue.Play('msg');
    }
    function JiguangInit(appkey: string, random_str: string, timestamp: string, signature: string) {
        JIM.init({
            "appkey": appkey,
            "random_str": random_str,
            "signature": signature,
            "timestamp": timestamp,
            "flag": 1
        }).onSuccess(function (data: any) {
            console.log('success:', uid);
            JIM.login({
                'username': uid,
                'password': pass
            }).onSuccess(function (data: any) {
                LoadFun && LoadFun(uid, data);
            });
        }).onFail(function (data: any) {
            console.log('error:', data);
        });
    }

    /***
     * 判断是否为平台管理用户
    */
    export function isAdmin(id:string){
        if(id=='mc_1'){
            return true;
        }else{
            return false;
        }
        /*
        if(id.indexOf('mc_')==0){
            id=MC.API.tihuan(id,'mc_','');
        }
        let adminlist=['1'];
        if(adminlist.indexOf(id)!==-1){
            return true;
        }else{
            return false;
        }*/
    }


}